#include<iostream>
#include<vector>
using namespace std;
int main () {
    int n = 1;
    while (1) {
        vector<int> map(10, 0);
        int s = n * n;
        int q = n * s;
        while (s != 0) {
            int temp = s % 10;
            s /= 10;
            map[temp]++;
            if (map[temp] > 1) break;
        }
        while (q != 0) {
            int temp = q % 10;
            q /= 10;
            map[temp]++;
            if (map[temp] > 1) break;
        }
        int i;
        for (i = 0; i < 10; i++) {
            if (map[i] != 1) {
                n++;
                break;
            } 
        }
        if (i == 10) {
            cout << n << endl;
            return 0;
        }
        else continue;
    }
    return 0;
}